home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
asm_n_z.zip
/
SDL32.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-08-16
|
25KB
|
1,003 lines
page 80,132
title SDL 3.2 - Sorted Directory List
sdl segment
sdlp proc far
assume cs:sdl,ds:sdl,es:sdl
;
; SORTED DIRECTORY LIST 3.2
;
; SDL [d:][path][filename[.ext]][/options]
;
; Options: General
; E erase screen
; P pause when screen full
; W 4 column format (2 if width 40)
; Sort options (sort on filename.ext is the default)
; N do not sort entries
; S sort by file size
; D sort by date and time
; X sort by file type (ext)
; Sub-directories
; T list sub-directory names
; F use with T to list file names by directory
; I use with TF to indent file lists (not supported on
; width 40 screens)
; A use with T to list all file names together
;
; Default: *.* sorted by name.ext, 2 cols wide (1 on width 40 screen), no
; screen erase or pause at end of page, using current directory.
;
; Notes:
; 1. Path specifications:
; a. paths must end with \.
; b. specifying a leading \ starts the path search at the root directory.
; No leading \ will start the path at the current directory.
; c. not specifying a path starts the operation at the current directory.
; 2. The space used by sub-directories is not accounted for.
; 3. Directory listings do not include the '.' or '..' entries.
; 4. The specified filename.ext may include ? and/or *.
;
; Output formats: Width 80 - 2 or 4 columns (option TFI - 1 or 2 columns)
; Width 40 - 1 or 2 columns
;
; Filename in listing may be preceeded by one of the following char.:
; r - read-only file
; h - hidden file
; s - system file
; \ - sub-directory name
; If a file has more than 1 attribute, only the last is shown.
;
; Written by W. C. Bodycomb
; Version 1.0 - original version, runs under DOS 1.0 and 1.1
; Version 2.0 - support for DOS 2.0, runs under DOS 1.0, 1.1, 2.0
; Version 3.0 - support for paths and sub-directories, runs under
; DOS 2.0.
; Version 3.2 - Sort in descending order for date and file size
; options. Make file extension ".*" by default. Fix MASM 3 errors.
; Reversed test for 80 column display because some MS-DOS systems do
; not use the fixed address that PC-DOS does. Print the directory
; name instead of "<curr>". Ted Shapin, 11/21/85.
;
org 100h ;set up for COM
subp proc near
;
; get current or specified drive
;
bgn: call clear ;clear ctrs
cld ;set direction
mov si,offset init ;init.
mov di,offset dxfcb ; the
mov cx,19 ; dummy
repz movsb ; FCB
mov ah,19h ;get
int 21h ; current
add al,65 ; disk
mov si,offset path ; and
mov [si],al ; save
mov di,80h ;get
mov ch,0 ; lth of
mov cl,[di] ; of param
jcxz vol1 ;br if no parms
inc di ;start of parms
mov al,' ' ;scan off
repe scasb ; blanks
je vol1 ;br if no parm
dec di ;adj
inc cx ; values
cmp cx,2 ;long enough
jb vol1 ;br no
cmp byte ptr [di]+1,':' ;is drive specified
jne vol1 ;br no
mov al,[di] ;save
and al,0dfh ; drive
mov [si],al ; letter
inc di ;incr
inc di ; adr
dec cx ;decr
dec cx ; count
;
; get volume label
;
vol1: push di ;save
push cx ; regs
mov dx,offset da ;set
mov ah,1ah ; dta
int 21h ; adr
mov al,[si] ;put drive
mov tia+9,al ; in header
sub al,64 ;set
mov byte ptr dfcb,al ; drive
mov di,offset svvol ;save area
mov ah,11h ;set get first
mov dx,offset dxfcb ;look for
int 21h ; vol label
or al,al ;any vol label
jnz fpth ;br no
mov si,offset da+8 ;label adr
mov cx,11 ;save
repz movsb ; label
;
; save specified path
;
fpth: mov byte ptr [di],' ' ;mark end
pop cx ;restore
pop di ; regs
jcxz fopt1 ;br if no path/fnm
mov dx,cx ;save count
mov bp,di ; and adr
add di,cx ;start
dec di ; at
std ; end
mov al,'\' ;find end
repne scasb ; of path
cld ;set direction
jne fopt ;br-not found
inc cx ;adj count
mov si,bp ;copy start adr
sub dx,cx ;save non-path lth
mov di,offset path+2 ;move
repz movsb ; path
mov fspca,di ;save path end adr
mov bp,si ;set new start adr
;
; get options
;
fopt: mov di,bp ;get start adr
mov cx,dx ; and lth
fopt1: jcxz eopt ;br-no options or filename
mov al,'/' ;find
repne scasb ; options
jne gfspc ;br-no options
dec di ;adj
inc cx ; values
mov si,di ;copy adr
push di ; and save
sub dx,cx ;save filespec size
opt: cmp byte ptr [si],'/' ;is it /
je opt3 ;keep looking
mov al,byte ptr [si] ;get char
and al,0dfh ;force upper case
mov di,offset swn ;set adr
mov bx,400h ; and flag
opt1: scasb ;option found
je opt2 ;br yes
shr bx,1 ;check next
jnz opt1 ; option
jz opt3 ;not valid option
opt2: or word ptr sw,bx ;set option
opt3: inc si ;check
loop opt ; all char
pop di ;restore reg
;
; get specified filespec
;
gfspc: mov byte ptr [di],' ' ;set delimiter
mov cx,dx ;get count
mov si,bp ; and adr
jcxz eopt ;br-no filespec
cmp byte ptr [si],' ' ;any filespec
je eopt ;br no
push di ;save end ptr
std ;look for filename extension
mov al,'.' ;by scanning for
repne scasb ;a period
cld ;reset to up
pop di ;restore pointer
je gfspc2 ;we found one
mov si,offset wild ;point to ".*"
movsb ;and move
movsb ;it
mov byte ptr [di],' ' ; add delimiter again
mov si,bp ;restore ptr to filespec
gfspc2: mov di,offset dfcb ;let DOS
mov ax,2900h ; parse
int 21h ; filespec
;
; initialize options
;
eopt: mov di,fspca ;move dir.
call mvfs ; filespec
test byte ptr sw1,4 ;T option
jnz eopt1 ;br yes
and byte ptr sw1,0fch ;clear A and F
eopt1: test byte ptr sw1,1 ;A option
jz eopt2 ;br no
and byte ptr sw1,0fdh ;clear F option
mov cx,19 ;set count
mov si,offset dirm ;change
mov di,offset h2+25 ; hdrs
repz movsb ; to dir#
eopt2: test byte ptr sw,8 ;wide
jz eopt3 ;br no
mov coln,4 ;set cols to 4
mov si,offset h3 ;hdr adr
mov di,offset h2+15 ;change
mov cx,5 ; bytes to
repz movsb ; sector
eopt3: push ds ;save data segment
mov ax,40h ;point to
mov ds,ax ; data area
mov ax,ds:4ah ;get screen cols
pop ds ;restore data segment
cmp ax,40 ;40 col
jne eopt4 ;br no
or byte ptr sw1,128 ;set 40 col
shr coln,1 ;cols
jnz fa ; /2
eopt4: test byte ptr sw1,2 ;option F
jz fa ;br no
test byte ptr sw,1 ;I option
jz fa ;br no
shr coln,1 ;cols/2
mov colp,40 ;set offset
;
; get FAT info
;
fa: mov dl,path ;get
sub dl,64 ; drive no
mov ah,36h ;get DOS 2
int 21h ; fat info
cmp ax,0ffffh ;br if
jne fa1 ; drive ok
int 20h ;give up
fa1: mov word ptr bpsc,cx ;save bytes/sec
mov ah,0 ;clear high byte
mov word ptr scpf,ax ;save sec/fat
xchg cx,dx ;find bytes per
mul dx ; alloc. unit
mul bx ;free bytes
mov word ptr free,ax ;save low
mov word ptr free+2,dx ; and high
;
; clear screen
;
clr: test byte ptr sw,128 ;screen clear
jz sdlh ;br no
sub cx,cx ;col 0, row 0
mov dx,184fh ;last row, col
test byte ptr sw1,128 ;80 cols
jz clr1 ;br yes
mov dx,1827h ;set 40 col
clr1: mov bh,7 ;color
mov ax,600h ;scroll
int 10h ; screen
sub dx,dx ;set
mov ah,2 ; cursor
mov bh,0 ; to
int 10h ; 0
;
; print SDL header
;
sdlh: mov dx,offset h1 ;print
call prt ; header
mov si,offset svvol ;label adr
sdlh1: lodsb ;get char
cmp al,' ' ;end of label
je sdlh2 ;br yes
mov dl,al ;print
call prtc ; char
jmp sdlh1 ;next char
sdlh2: mov ah,2ah ;get
int 21h ; date
mov si,offset mth ;field start
mov al,dh ;convert
call x2 ; month
mov al,dl ;convert
call x2 ; day
mov ax,cx ;adjust
sub ax,1900 ; year
call x2 ;convert year
mov ah,2ch ;get
int 21h ; time
mov si,offset ti ;field start
mov al,ch ;convert
call x2 ; hour
mov al,cl ;convert
call x2 ; minutes
mov dx,offset h1evl ;print
call prt ; hdr
test byte ptr sw1,128 ;width 40
jz sdlh3 ;br no
call ckpg ;print cr
sdlh3: mov dx,offset h1a ;print
call prt ; hdr
mov si,word ptr free ;convert